package main

import (
	"fmt"

	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

/*
在上面import "github.com/gin-gonic/gin"后，后执行go mod tidy会自动在go.mod中添加一堆require
*/

func runHttpServer() {
	gin.SetMode(gin.ReleaseMode)
	r := gin.New()

	// 跨域访问设置和默认Recovery
	r.Use(
		cors.New((cors.Config{
			AllowAllOrigins: true,
			AllowMethods:    []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
			AllowHeaders:    []string{"*"},
		})),
		gin.Recovery(),
	)

	// 设置路由组：http://127.0.0.1:4210/white/config
	router := r.Group("")
	router = router.Group("/white")
	config := router.Group("/config")

	//r.StaticFS("/static", http.Dir("./dist"))

	// "config"路由组需要验证
	//config.Use(mwBasicAuth("admin", "alongpswd"))

	// 注册GET/POST/PUT路由
	registerConfig(config)

	fmt.Println("http服务器启动。")
	// 在4210端口上运行这个HTTP服务。
	r.Run(":4210")
}
